package com.deliveryservicesystem.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 * File Name: Subscription.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.model.newpackage
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
@Entity
@Table(name = "SUBSCRIPTION")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Subscription.findAll", query = "SELECT s FROM Subscription s"),
    @NamedQuery(name = "Subscription.findBySubscriptionNo", query = "SELECT s FROM Subscription s WHERE s.subscriptionNo = :subscriptionNo"),
    @NamedQuery(name = "Subscription.findBySubscriptionDate", query = "SELECT s FROM Subscription s WHERE s.subscriptionDate = :subscriptionDate"),
    @NamedQuery(name = "Subscription.findByBaseAmount", query = "SELECT s FROM Subscription s WHERE s.baseAmount = :baseAmount"),
    @NamedQuery(name = "Subscription.findByTotalAmount", query = "SELECT s FROM Subscription s WHERE s.totalAmount = :totalAmount")
})
public class Subscription implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "SEQ_SUBSCRIPTION_NO", sequenceName = "SEQ_SUBSCRIPTION_NO")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_SUBSCRIPTION_NO")
    @Basic(optional = false)
    @Column(name = "SUBSCRIPTION_NO")
    private Integer subscriptionNo;
    @Column(name = "SUBSCRIPTION_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date subscriptionDate;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Basic(optional = false)
    @Column(name = "BASE_AMOUNT")
    private double baseAmount;
    @Column(name = "TOTAL_AMOUNT")
    private double totalAmount;
    @OneToMany(mappedBy = "subscriptionNo")
    private List<Product> productList;
    @JoinColumn(name = "DELIVERY_NO", referencedColumnName = "DELIVERY_NO")
    @ManyToOne
    private Delivery deliveryNo;
    @JoinColumn(name = "CUSTOMER_NO", referencedColumnName = "CUSTOMER_NO")
    @ManyToOne
    private Customer customerNo;
    @JoinColumn(name = "BILLING_NO", referencedColumnName = "BILLING_NO")
    @ManyToOne
    private Billing billingNo;

    public Subscription()
    {
    }

    public Subscription(Integer subscriptionNo)
    {
        this.subscriptionNo = subscriptionNo;
    }

    public Subscription(Integer subscriptionNo, double baseAmount)
    {
        this.subscriptionNo = subscriptionNo;
        this.baseAmount = baseAmount;
    }

    public Integer getSubscriptionNo()
    {
        return subscriptionNo;
    }

    public void setSubscriptionNo(Integer subscriptionNo)
    {
        this.subscriptionNo = subscriptionNo;
    }

    public Date getSubscriptionDate()
    {
        return subscriptionDate;
    }

    public void setSubscriptionDate(Date subscriptionDate)
    {
        this.subscriptionDate = subscriptionDate;
    }

    public double getBaseAmount()
    {
        return baseAmount;
    }

    public void setBaseAmount(double baseAmount)
    {
        this.baseAmount = baseAmount;
    }

    public double getTotalAmount()
    {
        return totalAmount;
    }

    public void setTotalAmount(double totalAmount)
    {
        this.totalAmount = totalAmount;
    }

    @XmlTransient
    public List<Product> getProductList()
    {
        return productList;
    }

    public void setProductList(List<Product> productList)
    {
        this.productList = productList;
    }

    public Delivery getDeliveryNo()
    {
        return deliveryNo;
    }

    public void setDeliveryNo(Delivery deliveryNo)
    {
        this.deliveryNo = deliveryNo;
    }

    public Customer getCustomerNo()
    {
        return customerNo;
    }

    public void setCustomerNo(Customer customerNo)
    {
        this.customerNo = customerNo;
    }

    public Billing getBillingNo()
    {
        return billingNo;
    }

    public void setBillingNo(Billing billingNo)
    {
        this.billingNo = billingNo;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (subscriptionNo != null ? subscriptionNo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Subscription))
        {
            return false;
        }
        Subscription other = (Subscription) object;
        if ((this.subscriptionNo == null && other.subscriptionNo != null) || (this.subscriptionNo != null && !this.subscriptionNo.equals(other.subscriptionNo)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "Subscription Number: " + subscriptionNo
                + "\nSubscription Date: " + subscriptionDate
                + "\nBase Amount: " + baseAmount
                + "\nTotal Amount: " + totalAmount
                + "\nDelivery Number:" + deliveryNo.getDeliveryNo()
                + "\nCustomer Number:" + customerNo.getCustomerNo()
                + "\nBilling Number: " + billingNo.getBillingNo();
    }
}
